home *** CD-ROM | disk | FTP | other *** search
/ Megahits 5 / Megahits 5 (1994)(GTI - Rhein-Main-Soft)(DE)(Disc 2 of 2)[!].iso / archive / show / jpegagasrc10.lha / jpegaga / jpegAGA.c < prev    next >
C/C++ Source or Header  |  1994-06-04  |  21KB  |  592 lines

  1. /* jpegAGA written by Günther Röhrich                */
  2. /* this file is based on example.c, which is part of */
  3. /* the Independent JPEG Group's JPEG software        */
  4.  
  5.  
  6. #include "jinclude.h"
  7.  
  8.  
  9. /*
  10.  * <setjmp.h> is used for the optional error recovery mechanism shown in
  11.  * the second part of the example.
  12.  */
  13.  
  14. #include <setjmp.h>
  15. #include <signal.h> 
  16.  
  17. /* definitions for display.c */
  18.  
  19. #define HAM8 1
  20.  
  21. #ifdef __GNUC__
  22. #define MYSTRCMP strcasecmp
  23. #define MYSTRNCMP strncasecmp
  24. #else
  25. #define MYSTRCMP strcmp
  26. #define MYSTRNCMP strncmp
  27. #endif
  28.  
  29.  
  30. char  *ver = "\0$VER: jpegAGA 1.0 (4.6.94)";
  31. int VGAenable = 0;
  32. static int GrayEnable=0;
  33. static int BlockSmoothing=0;
  34. static FILE *ColorMapFile=NULL;
  35. char MapFileName[120];
  36.  
  37. extern int InitDisplay(int cols, int rows, unsigned long Mode, int NumPlanes);
  38. extern void SetDisplayColor(int ColorNumber, unsigned char r, unsigned char g, unsigned char b);
  39. extern void CloseDisplay(void);
  40. extern void DisplayRow(char *array, int cols);
  41. extern int CheckButton(void);
  42. extern void FinalWait(void);
  43. JSAMPROW OutputBuffer=NULL;
  44.  
  45. extern void EncodeHAM8(char *rorig, char *gorig, char *borig, char *yham, int xsize);
  46. unsigned short Mult_Table[2*256];
  47.  
  48.  
  49. /* NOTE: this array is in brgbrg order */
  50. /* when a mapfile is available it will be overwritten */
  51.  
  52. char *ColorCache;
  53. unsigned char ColorTable[64*3] =
  54.  { 0, 0, 0,  4, 4, 4,  8, 8, 8, 12,12,12,   
  55.   16,16,16, 20,20,20, 24,24,24, 28,28,28,  /* 16 colors */
  56.   32,32,32, 36,36,36, 41,41,41, 46,46,46,
  57.   51,51,51, 55,55,55, 59,59,59, 63,63,63,
  58.  
  59.  
  60.                       17,17,39, 17,17,55, /* 13 colors */ 
  61.   17,29,17,           17,29,39, 17,29,55, 
  62.   17,39,17, 17,39,29, 17,39,39, 17,39,55,
  63.   17,55,17, 17,55,39, 17,55,39, 17,55,55,
  64.  
  65.  
  66.             29,17,29, 29,17,39, 29,17,55, /* 11 colors */
  67.                                 29,29,55,
  68.   29,39,17, 29,39,29,           29,39,55,
  69.   29,55,17, 29,55,29, 29,55,39, 29,55,55,
  70.  
  71.  
  72.   39,17,17, 39,17,29, 39,17,39, 39,17,55, /* 12 colors */
  73.   39,29,17, 39,29,29,           39,29,55,
  74.   39,39,17, 39,39,29,          
  75.   39,55,17, 39,55,29,  
  76.  
  77.   
  78.   55,17,17, 55,17,29, 55,17,39, 55,17,55, /* 13 colors */
  79.   55,29,27, 55,29,29, 55,29,39, 55,29,55,
  80.   55,39,17, 55,39,29, 55,39,39, 
  81.   55,55,17, 55,55,29
  82. };
  83.  
  84.  
  85.  
  86.  
  87.  
  88. /******************** JPEG DECOMPRESSION SAMPLE INTERFACE *******************/
  89.  
  90. /* This half of the example shows how to read data from the JPEG decompressor.
  91.  * It's a little more refined than the above in that we show how to do your
  92.  * own error recovery.  If you don't care about that, you don't need these
  93.  * next two routines.
  94.  */
  95.  
  96.  
  97. /*
  98.  * These routines replace the default trace/error routines included with the
  99.  * JPEG code.  The example trace_message routine shown here is actually the
  100.  * same as the standard one, but you could modify it if you don't want messages
  101.  * sent to stderr.  The example error_exit routine is set up to return
  102.  * control to read_JPEG_file() rather than calling exit().  You can use the
  103.  * same routines for both compression and decompression error recovery.
  104.  */
  105.  
  106. /* These static variables are needed by the error routines. */
  107. static jmp_buf setjmp_buffer;    /* for return to caller */
  108. static external_methods_ptr emethods; /* needed for access to message_parm */
  109.  
  110.  
  111. /* This routine is used for any and all trace, debug, or error printouts
  112.  * from the JPEG code.  The parameter is a printf format string; up to 8
  113.  * integer data values for the format string have been stored in the
  114.  * message_parm[] field of the external_methods struct.
  115.  */
  116.  
  117. METHODDEF void
  118. trace_message (const char *msgtext)
  119. {
  120.   fprintf(stderr, msgtext,
  121.       emethods->message_parm[0], emethods->message_parm[1],
  122.       emethods->message_parm[2], emethods->message_parm[3],
  123.       emethods->message_parm[4], emethods->message_parm[5],
  124.       emethods->message_parm[6], emethods->message_parm[7]);
  125.   fprintf(stderr, "\n");    /* there is no \n in the format string! */
  126. }
  127.  
  128. /*
  129.  * The error_exit() routine should not return to its caller.  The default
  130.  * routine calls exit(), but here we assume that we want to return to
  131.  * read_JPEG_file, which has set up a setjmp context for the purpose.
  132.  * You should make sure that the free_all method is called, either within
  133.  * error_exit or after the return to the outer-level routine.
  134.  */
  135.  
  136. void
  137. error_exit (const char *msgtext)
  138. {
  139.   trace_message(msgtext);    /* report the error message */
  140.   (*emethods->free_all) ();    /* clean up memory allocation & temp files */
  141.   longjmp(setjmp_buffer, 1);    /* return control to outer routine */
  142. }
  143.  
  144.  
  145.  
  146. /*
  147.  * To accept the image data from decompression, you must define four routines
  148.  * output_init, put_color_map, put_pixel_rows, and output_term.
  149.  *
  150.  * You must understand the distinction between full color output mode
  151.  * (N independent color components) and colormapped output mode (a single
  152.  * output component representing an index into a color map).  You should use
  153.  * colormapped mode to write to a colormapped display screen or output file.
  154.  * Colormapped mode is also useful for reducing grayscale output to a small
  155.  * number of gray levels: when using the 1-pass quantizer on grayscale data,
  156.  * the colormap entries will be evenly spaced from 0 to MAX_JSAMPLE, so you
  157.  * can regard the indexes are directly representing gray levels at reduced
  158.  * precision.  In any other case, you should not depend on the colormap
  159.  * entries having any particular order.
  160.  * To get colormapped output, set cinfo->quantize_colors to TRUE and set
  161.  * cinfo->desired_number_of_colors to the maximum number of entries in the
  162.  * colormap.  This can be done either in your main routine or in
  163.  * d_ui_method_selection.  For grayscale quantization, also set
  164.  * cinfo->two_pass_quantize to FALSE to ensure the 1-pass quantizer is used
  165.  * (presently this is the default, but it may not be so in the future).
  166.  *
  167.  * The output file writing modules (jwrppm.c, jwrgif.c, jwrtarga.c, etc) may be
  168.  * useful examples of what these routines should actually do, although each of
  169.  * them is encrusted with a lot of specialized code for its own file format.
  170.  */
  171.  
  172.  
  173. METHODDEF void
  174. output_init (decompress_info_ptr cinfo)
  175. /* This routine should do any setup required */
  176. {
  177.   /* This routine can initialize for output based on the data passed in cinfo.
  178.    * Useful fields include:
  179.    *    image_width, image_height    Pretty obvious, I hope.
  180.    *    data_precision            bits per pixel value; typically 8.
  181.    *    out_color_space            output colorspace previously requested
  182.    *    color_out_comps            number of color components in same
  183.    *    final_out_comps            number of components actually output
  184.    * final_out_comps is 1 if quantize_colors is true, else it is equal to
  185.    * color_out_comps.
  186.    *
  187.    * If you have requested color quantization, the colormap is NOT yet set.
  188.    * You may wish to defer output initialization until put_color_map is called.
  189.    */
  190.  
  191.   int DisplaySuccess, i;
  192.   
  193.   if(cinfo->out_color_space == CS_GRAYSCALE)
  194.   {
  195.     DisplaySuccess = InitDisplay(cinfo->image_width, cinfo->image_height, 0, 8);
  196.     if(DisplaySuccess != 1)
  197.     {
  198.       CloseDisplay();
  199.       error_exit("Could not open display!");
  200.     }
  201.     for(i=0; i<256; i++) SetDisplayColor(i, (unsigned char)i, (unsigned char)i, (unsigned char)i);
  202.   }
  203.   else
  204.   {
  205.     ColorCache = calloc(262145, 1);
  206.     if(ColorCache == NULL) error_exit("Out of memory.");
  207.  
  208.     /* create the multiplication table */
  209.     for(i=-255; i<256; i++) Mult_Table[i+255] = (unsigned short)(i*i);
  210.  
  211.     printf("Using HAM8-Mode");
  212.  
  213.     strcat(MapFileName, ".map");
  214.     ColorMapFile = fopen(MapFileName, "r");
  215.     if(!ColorMapFile)
  216.     {
  217.       int i = strlen(MapFileName) - 4;
  218.       while(i > 0 && MapFileName[i-1] != '.') i--;
  219.       if(MapFileName[i-1] == '.')
  220.       {
  221.         strcpy(&MapFileName[i], "map");
  222.         ColorMapFile = fopen(MapFileName, "r");
  223.       }
  224.     }
  225.  
  226.     if(ColorMapFile)
  227.     {
  228.       unsigned short MagicNumber;
  229.       unsigned int Reserved;
  230.  
  231.       if(fread(&MagicNumber, 2, 1, ColorMapFile) != 1) error_exit("Read error in mapfile");
  232.       if(MagicNumber != 0x1203) error_exit("Wrong mapfile header!");    
  233.       if(fread(&Reserved,    4, 1, ColorMapFile) != 1) error_exit("Read error in mapfile");
  234.       if(fread(ColorTable,  64*3, 1, ColorMapFile) != 1) error_exit("Read error in mapfile");
  235.  
  236.       printf(" with mapfile");
  237.       fclose(ColorMapFile);
  238.       ColorMapFile = NULL;
  239.     }
  240.  
  241.     printf("\n");
  242.  
  243.     printf("Width: %d, Height: %d\n", (int)cinfo->image_width, (int)cinfo->image_height);
  244.  
  245.     DisplaySuccess = InitDisplay(cinfo->image_width, cinfo->image_height, HAM8, 8);
  246.     if(DisplaySuccess != 1)
  247.     {
  248.       CloseDisplay();
  249.       error_exit("Could not open display!");
  250.     }
  251.     for(i=0; i<64; i++) SetDisplayColor(i, ColorTable[i*3+1]<<2, 
  252.                                            ColorTable[i*3+2]<<2,
  253.                                            ColorTable[i*3]<<2);
  254.   }
  255.  
  256.   OutputBuffer = malloc(((cinfo->image_width+15)>>4)<<4);
  257.   if(!OutputBuffer) error_exit("Out of memory.");
  258.      
  259. }
  260.  
  261.  
  262. /*
  263.  * This routine is called if and only if you have set cinfo->quantize_colors
  264.  * to TRUE.  It is given the selected colormap and can complete any required
  265.  * initialization.  This call will occur after output_init and before any
  266.  * calls to put_pixel_rows.  Note that the colormap pointer is also placed
  267.  * in a cinfo field, whence it can be used by put_pixel_rows or output_term.
  268.  * num_colors will be less than or equal to desired_number_of_colors.
  269.  *
  270.  * The colormap data is supplied as a 2-D array of JSAMPLEs, indexed as
  271.  *        JSAMPLE colormap[component][indexvalue]
  272.  * where component runs from 0 to cinfo->color_out_comps-1, and indexvalue
  273.  * runs from 0 to num_colors-1.  Note that this is actually an array of
  274.  * pointers to arrays rather than a true 2D array, since C does not support
  275.  * variable-size multidimensional arrays.
  276.  * JSAMPLE is typically typedef'd as "unsigned char".  If you want your code
  277.  * to be as portable as the JPEG code proper, you should always access JSAMPLE
  278.  * values with the GETJSAMPLE() macro, which will do the right thing if the
  279.  * machine has only signed chars.
  280.  */
  281.  
  282. METHODDEF void
  283. put_color_map (decompress_info_ptr cinfo, int num_colors, JSAMPARRAY colormap)
  284. /* Write the color map */
  285. {
  286.   /* You need not provide this routine if you always set cinfo->quantize_colors
  287.    * FALSE; but a safer practice is to provide it and have it just print an
  288.    * error message, like this:
  289.    */
  290.   fprintf(stderr, "put_color_map called: there's a bug here somewhere!\n");
  291. }
  292.  
  293.  
  294. /*
  295.  * This function is called repeatedly, with a few more rows of pixels supplied
  296.  * on each call.  With the current JPEG code, some multiple of 8 rows will be
  297.  * passed on each call except the last, but it is extremely bad form to depend
  298.  * on this.  You CAN assume num_rows > 0.
  299.  * The data is supplied in top-to-bottom row order (the standard order within
  300.  * a JPEG file).  If you cannot readily use the data in that order, you'll
  301.  * need an intermediate array to hold the image.  See jwrrle.c for an example
  302.  * of outputting data in bottom-to-top order.
  303.  *
  304.  * The data is supplied as a 3-D array of JSAMPLEs, indexed as
  305.  *        JSAMPLE pixel_data[component][row][column]
  306.  * where component runs from 0 to cinfo->final_out_comps-1, row runs from 0 to
  307.  * num_rows-1, and column runs from 0 to cinfo->image_width-1 (column 0 is
  308.  * left edge of image).  Note that this is actually an array of pointers to
  309.  * pointers to arrays rather than a true 3D array, since C does not support
  310.  * variable-size multidimensional arrays.
  311.  * JSAMPLE is typically typedef'd as "unsigned char".  If you want your code
  312.  * to be as portable as the JPEG code proper, you should always access JSAMPLE
  313.  * values with the GETJSAMPLE() macro, which will do the right thing if the
  314.  * machine has only signed chars.
  315.  *
  316.  * If quantize_colors is true, then there is only one component, and its values
  317.  * are indexes into the previously supplied colormap.  Otherwise the values
  318.  * are actual data in your selected output colorspace.
  319.  */
  320.  
  321.  
  322. METHODDEF void
  323. put_pixel_rows (decompress_info_ptr cinfo, int num_rows, JSAMPIMAGE pixel_data)
  324. /* Write some rows of output data */
  325. {
  326.   /* This example shows how you might write full-color RGB data (3 components)
  327.    * to an output file in which the data is stored 3 bytes per pixel.
  328.    */
  329.   register JSAMPROW ptr0, ptr1, ptr2;
  330.   register int row;
  331.   
  332.   for (row = 0; row < num_rows; row++) 
  333.   {
  334.     ptr0 = pixel_data[0][row];
  335.     ptr1 = pixel_data[1][row];
  336.     ptr2 = pixel_data[2][row];
  337.  
  338.     if(CheckButton())
  339.     {
  340.       CloseDisplay();
  341.       error_exit("Display stopped.");
  342.     }
  343.  
  344.     EncodeHAM8(ptr0, ptr1, ptr2, OutputBuffer, cinfo->image_width);
  345.     
  346.     DisplayRow(OutputBuffer, cinfo->image_width);
  347.   }
  348. }
  349.  
  350. METHODDEF void
  351. put_gray_rows (decompress_info_ptr cinfo, int num_rows,
  352.            JSAMPIMAGE pixel_data)
  353. {
  354.   register JSAMPROW ptr0;
  355.   register long col;
  356.   long width = cinfo->image_width;
  357.   int row;
  358.  
  359.   if(CheckButton())
  360.   {
  361.     CloseDisplay();
  362.     error_exit("Display stopped.");
  363.   }
  364.  
  365.   for (row = 0; row < num_rows; row++)
  366.   {
  367.     memcpy(OutputBuffer, pixel_data[0][row], width);
  368.     DisplayRow(OutputBuffer, width);  
  369.   }
  370. }
  371.  
  372.  
  373. METHODDEF void
  374. output_term (decompress_info_ptr cinfo)
  375. /* Finish up at the end of the output */
  376. {
  377.   /* This termination routine may not need to do anything. */
  378.   /* Note that the JPEG code will only call it during successful exit; */
  379.   /* if you want it called during error exit, you gotta do that yourself. */
  380. }
  381.  
  382.  
  383. /*
  384.  * That's it for the routines that deal with writing the output image.
  385.  * Now we have overall control and parameter selection routines.
  386.  */
  387.  
  388.  
  389. /*
  390.  * This routine gets control after the JPEG file header has been read;
  391.  * at this point the image size and colorspace are known.
  392.  * The routine must determine what output routines are to be used, and make
  393.  * any decompression parameter changes that are desirable.  For example,
  394.  * if it is found that the JPEG file is grayscale, you might want to do
  395.  * things differently than if it is color.  You can also delay setting
  396.  * quantize_colors and associated options until this point. 
  397.  *
  398.  * j_d_defaults initializes out_color_space to CS_RGB.  If you want grayscale
  399.  * output you should set out_color_space to CS_GRAYSCALE.  Note that you can
  400.  * force grayscale output from a color JPEG file (though not vice versa).
  401.  */
  402.  
  403. METHODDEF void
  404. d_ui_method_selection (decompress_info_ptr cinfo)
  405. {
  406.   /* if grayscale input, force grayscale output; */
  407.   /* else leave the output colorspace as set by main routine. */
  408.   if (cinfo->jpeg_color_space == CS_GRAYSCALE || GrayEnable == 1)
  409.   {
  410.     cinfo->out_color_space = CS_GRAYSCALE; 
  411.     cinfo->methods->put_pixel_rows = put_gray_rows;
  412.   }
  413.   else
  414.   {
  415.     cinfo->methods->put_pixel_rows = put_pixel_rows; 
  416.   }
  417.     
  418.  
  419.   /* select output routines */
  420.   cinfo->methods->output_init = output_init;
  421.   cinfo->methods->put_color_map = put_color_map;
  422.   cinfo->methods->output_term = output_term;
  423. }
  424.  
  425.  
  426. /*
  427.  * OK, here is the main function that actually causes everything to happen.
  428.  * We assume here that the JPEG filename is supplied by the caller of this
  429.  * routine, and that all decompression parameters can be default values.
  430.  * The routine returns 1 if successful, 0 if not.
  431.  */
  432.  
  433. GLOBAL int
  434. read_JPEG_file (char * filename)
  435. {
  436.   /* These three structs contain JPEG parameters and working data.
  437.    * They must survive for the duration of parameter setup and one
  438.    * call to jpeg_decompress; typically, making them local data in the
  439.    * calling routine is the best strategy.
  440.    */
  441.   struct Decompress_info_struct cinfo;
  442.   struct Decompress_methods_struct dc_methods;
  443.   struct External_methods_struct e_methods;
  444.  
  445.   /* Select the input and output files.
  446.    * In this example we want to open the input file before doing anything else,
  447.    * so that the setjmp() error recovery below can assume the file is open.
  448.    * Note that cinfo.output_file is only used if your output handling routines
  449.    * use it; otherwise, you can just make it NULL.
  450.    * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
  451.    * requires it in order to read binary files.
  452.    */
  453.  
  454.   if ((cinfo.input_file = fopen(filename, "rb")) == NULL) {
  455.     fprintf(stderr, "can't open %s\n", filename);
  456.     return 0;
  457.   }
  458.  
  459.   cinfo.output_file = NULL;    /* if no actual output file involved */
  460.  
  461.   /* Initialize the system-dependent method pointers. */
  462.   cinfo.methods = &dc_methods;    /* links to method structs */
  463.   cinfo.emethods = &e_methods;
  464.   /* Here we supply our own error handler; compare to use of standard error
  465.    * handler in the previous write_JPEG_file example.
  466.    */
  467.   emethods = &e_methods;    /* save struct addr for possible access */
  468.   e_methods.error_exit = error_exit; /* supply error-exit routine */
  469.   e_methods.trace_message = trace_message; /* supply trace-message routine */
  470.   e_methods.trace_level = 0;    /* default = no tracing */
  471.   e_methods.num_warnings = 0;    /* no warnings emitted yet */
  472.   e_methods.first_warning_level = 0; /* display first corrupt-data warning */
  473.   e_methods.more_warning_level = 3; /* but suppress additional ones */
  474.  
  475.   /* prepare setjmp context for possible exit from error_exit */
  476.   if (setjmp(setjmp_buffer)) {
  477.     /* If we get here, the JPEG code has signaled an error.
  478.      * Memory allocation has already been cleaned up (see free_all call in
  479.      * error_exit), but we need to close the input file before returning.
  480.      * You might also need to close an output file, etc.
  481.      */
  482.     fclose(cinfo.input_file);
  483.     CloseDisplay();
  484.     return 10;
  485.   }
  486.  
  487.   /* Here we use the standard memory manager provided with the JPEG code.
  488.    * In some cases you might want to replace the memory manager, or at
  489.    * least the system-dependent part of it, with your own code.
  490.    */
  491.   jselmemmgr(&e_methods);    /* select std memory allocation routines */
  492.   /* If the decompressor requires full-image buffers (for two-pass color
  493.    * quantization or a noninterleaved JPEG file), it will create temporary
  494.    * files for anything that doesn't fit within the maximum-memory setting.
  495.    * You can change the default maximum-memory setting by changing
  496.    * e_methods.max_memory_to_use after jselmemmgr returns.
  497.    * On some systems you may also need to set up a signal handler to
  498.    * ensure that temporary files are deleted if the program is interrupted.
  499.    * (This is most important if you are on MS-DOS and use the jmemdos.c
  500.    * memory manager back end; it will try to grab extended memory for
  501.    * temp files, and that space will NOT be freed automatically.)
  502.    * See jcmain.c or jdmain.c for an example signal handler.
  503.    */
  504.  
  505.   /* Here, set up the pointer to your own routine for post-header-reading
  506.    * parameter selection.  You could also initialize the pointers to the
  507.    * output data handling routines here, if they are not dependent on the
  508.    * image type.
  509.    */
  510.   dc_methods.d_ui_method_selection = d_ui_method_selection;
  511.  
  512.   /* Set up default decompression parameters. */
  513.   j_d_defaults(&cinfo, TRUE);
  514.   /* TRUE indicates that an input buffer should be allocated.
  515.    * In unusual cases you may want to allocate the input buffer yourself;
  516.    * see jddeflts.c for commentary.
  517.    */
  518.  
  519.   /* At this point you can modify the default parameters set by j_d_defaults
  520.    * as needed; for example, you can request color quantization or force
  521.    * grayscale output.  See jdmain.c for examples of what you might change.
  522.    */
  523.  
  524.    /* if(GrayEnable) cinfo.out_color_space = CS_GRAYSCALE; */ /* force grayscale output */
  525.    if(BlockSmoothing) cinfo.do_block_smoothing = TRUE; 
  526.  
  527.   /* Set up to read a JFIF or baseline-JPEG file. */
  528.   /* This is the only JPEG file format currently supported. */
  529.   jselrjfif(&cinfo);
  530.  
  531.   /* Here we go! */
  532.   jpeg_decompress(&cinfo);
  533.  
  534.   /* That's it, son.  Nothin' else to do, except close files. */
  535.   /* Here we assume only the input file need be closed. */
  536.   fclose(cinfo.input_file);
  537.   FinalWait();
  538.   CloseDisplay();
  539.  
  540.   /* You might want to test e_methods.num_warnings to see if bad data was
  541.    * detected.  In this example, we just blindly forge ahead.
  542.    */
  543.   return 1;            /* indicate success */
  544.  
  545.   /* Note: if you want to decompress more than one image, we recommend you
  546.    * repeat this whole routine.  You MUST repeat the j_d_defaults()/alter
  547.    * parameters/jpeg_decompress() sequence, as some data structures allocated
  548.    * in j_d_defaults are freed upon exit from jpeg_decompress.
  549.    */
  550. }
  551.  
  552.  
  553. static void Usage(void)
  554. {
  555.  printf("Usage: jpegAGA file [switches]\n"
  556.         "switches: -GRAY  force grayscale output\n"
  557.         "          -BS    do block smoothing\n"
  558.         "          -VGA   use VGA screenmode\n");
  559.  exit(10);
  560. }
  561.  
  562. int main(int argc, char *argv[])
  563. {
  564.  int i;
  565.  signal(SIGINT, SIG_IGN); /* disable CTRL-C handling */
  566.  printf("jpegAGA V1.0 by Günther Röhrich. This program is Public Domain.\n");
  567.  
  568.  /* remove the comments for beta versions */
  569.  /* printf("Preliminary version. DO NOT SPREAD IT!\n"); */
  570.  
  571.  if(argc < 2) Usage();
  572.  
  573.  for(i=2; i<argc; i++)
  574.  {
  575.    #ifndef __GNUC__
  576.    strupr(argv[i]);
  577.    #endif
  578.    if(!MYSTRNCMP(argv[i], "-GRAY", 5)) GrayEnable=1;
  579.  
  580.    else if(!MYSTRNCMP(argv[i], "-BS", 3)) BlockSmoothing=1;    
  581.  
  582.    else if(!MYSTRNCMP(argv[i], "-VGA", 4)) VGAenable=1;
  583.    
  584.    else Usage();
  585.  }    
  586.  
  587.  strncpy(MapFileName, argv[1], 115); /* create a copy of the file name */
  588.  read_JPEG_file(argv[1]);
  589.  return 0;
  590. }
  591.  
  592.